package com.idig8.day02;

import com.idig8.until.TimeTool;

public class SumNumber {
    public static Long sum1(int n){
        Long result = 0l;
        for (int i = 0; i<=n;i++) {
            result += i;
        }
        return result;
    }

    public static Long sum2(int n){
        return (1+n) * n / 2l;
    }

    public static void main(String[] args){
        TimeTool.getTime(() -> {
            System.out.println("通过for循环查询从1加到n："+sum1(10000));

        });

        TimeTool.getTime(() -> {
            System.out.println("通过数学运算："+sum2(10000));

        });

    }


}
